version: "3"

services:
  postgres:
    image: postgres:15.2
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB_NAME}
    env_file:
      - .env
    expose:
      - "${POSTGRES_PORT}"
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    networks:
      - backend_network

  api:
    build:
      context: .
    container_name: api
    image: fastapi_app
    restart: always
    entrypoint: ["/opt/app/entrypoint.sh"]
    env_file:
      - .env
    expose:
      - "${API_PORT}"
    ports:
      - "${API_PORT}:${API_PORT}"
    depends_on:
      - postgres
    networks:
      - backend_network
      - api_network

  nginx:
    image: nginx:1.25.1
    env_file:
      - .env
    ports:
      - "${NGINX_PORT}:${NGINX_PORT}"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/templates:/etc/nginx/templates
    depends_on:
      - api
    networks:
      - api_network

volumes:
  postgres_data:

networks:
  api_network:
    driver: bridge
  backend_network:
    driver: bridge